﻿<cfscript>
/** 
* ORM Classroom
* 
* @hint "Hibernate persistenter t_classroom. 教室基本情况的一些基本数据项" 
* 
*/ 

component 
	displayname="public.service.orm.senate.Classroom" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="Classroom" 
	table="t_classroom"
	{

	property type="string" name="ClassroomID" column="cr_id" fieldtype="id" generator="assigned" hint="教室号";
	
	property type="string" name="Name" column="classroom" hint="教室名称";
	property type="string" name="Floor" column="cr_floor" hint="所在楼层";
	property type="string" name="Usage" column="cr_usage" hint="教室用途";

	property type="numeric" name="SitCount" column="sits" hint="座位数";
	property type="numeric" name="SitForCourse" column="sits_course" hint="排课座位数";
	property type="numeric" name="SitForExam" column="sits_exam" hint="考试座位数";

	property name="TimeTables" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="cr_id" cfc="ClassroomTimeTable" hint="教室时间占用情况表";
	property name="Examers" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="cr_id" cfc="StudentExam" hint="学生学期考试安排表";
	property name="ResitExamers" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="cr_id" cfc="StudentExamResit" hint="学生学期补考安排表";

	property name="Campus" fieldtype="many-to-one" fkcolumn="campus_id" cfc="Campus"  hint="校区代码";
	property name="Building" fieldtype="many-to-one" fkcolumn="b_id" cfc="Building"  hint="建筑物号";
	property name="ClassroomType" fieldtype="many-to-one" fkcolumn="cr_type" cfc="ClassroomType"  hint="教室类型代码";
	property name="ClassroomPurpose" fieldtype="many-to-one" fkcolumn="cr_purpose" cfc="RoomPurpose"  hint="教学及辅助用房用途代码";

	/**
	* @hint "自定义主键规则"
	* 
	* @Building "教学楼"
	* @Floor "楼层"
	*/
	public string function getNextID( required Building, required string Floor ) output=false {
		
		var nextID = arguments.Building.getBuildingID() & arguments.Floor & numberFormat(1, "0___");
		var checkArray = ORMExecuteQuery("select ClassroomID from Classroom 
											where 
											Building = :building 
											and
											Floor = :floor
											and
											ClassroomID like :condition
											order by ClassroomID desc", {building = arguments.Building, floor = arguments.Floor, condition = arguments.Building.getBuildingID() & arguments.Floor & "____" }, { maxResults=1 });
		
		/* 
			主键生成规则 CHAR(12)
		
			6位楼宇代码 + 2位楼层标识 + 4位为流水号
			
			其中所在楼层标识 01 表示 第一楼, B1 表示 地下1楼 地下标识可能用于地势复杂区域 存在入口在楼宇中央的情景
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.Building.getBuildingID() & arguments.Floor & numberFormat((right(checkArray[1], 4) + 1), "0___");
			
		}

		return nextID;
		
	}
	
}

</cfscript>